package com.lcl.jarvis.admin.modules.business.service.impl;

import java.util.List;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import com.lcl.jarvis.common.model.PageResult;
import com.lcl.jarvis.admin.modules.business.dto.request.TbMedicalInfoReqDTO;
import com.lcl.jarvis.admin.modules.business.dto.response.TbMedicalInfoRespDTO;
import com.lcl.jarvis.admin.modules.business.dto.request.TbMedicalInfoPageReqDTO;

import com.lcl.jarvis.admin.modules.business.mapper.TbMedicalInfoMapper;
import com.lcl.jarvis.admin.modules.business.entity.TbMedicalInfo;
import com.lcl.jarvis.admin.modules.business.service.ITbMedicalInfoService;
import lombok.RequiredArgsConstructor;

/**
 * 医疗机构信息Service业务层处理
 *
 * @author licl
 * @date 2024-06-21 11:11:22
 */
@Service
@RequiredArgsConstructor
public class TbMedicalInfoServiceImpl extends ServiceImpl<TbMedicalInfoMapper, TbMedicalInfo> implements ITbMedicalInfoService {

    /**
     * 新增医疗机构信息
     *
     * @param body 医疗机构信息
     * @return 结果
     */
    @Override
    public Integer add(TbMedicalInfoReqDTO body) {
        TbMedicalInfo entity = BeanUtil.copyProperties(body, TbMedicalInfo.class);
        return baseMapper.insert(entity);
    }

    /**
     * 批量删除医疗机构信息
     *
     * @param ids 需要删除的医疗机构信息主键
     * @return 结果
     */
    @Override
    public Integer remove(List<Long> ids) {
        return baseMapper.deleteByIds(ids);
    }

    /**
     * 修改医疗机构信息
     *
     * @param body 医疗机构信息
     * @return 结果
     */
    @Override
    public Integer update(TbMedicalInfoReqDTO body) {
        TbMedicalInfo entity = BeanUtil.copyProperties(body, TbMedicalInfo.class);

        return baseMapper.updateById(entity);
    }


    /**
     * 查询医疗机构信息
     *
     * @param id 医疗机构信息主键
     * @return 医疗机构信息
     */
    @Override
    public TbMedicalInfoRespDTO detail(Long id) {
        TbMedicalInfo entity = baseMapper.selectById(id);
        return BeanUtil.copyProperties(entity, TbMedicalInfoRespDTO.class);
    }

    /**
     * 查询医疗机构信息列表
     *
     * @param req
     * @return 医疗机构信息
     */
    @Override
    public PageResult<TbMedicalInfoRespDTO> page(TbMedicalInfoPageReqDTO req) {
        LambdaQueryWrapper<TbMedicalInfo> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(StrUtil.isNotBlank(req.getCode()), TbMedicalInfo::getCode, req.getCode());
        queryWrapper.like(StrUtil.isNotBlank(req.getName()), TbMedicalInfo::getName, req.getName());
        queryWrapper.eq(StrUtil.isNotBlank(req.getAddress()), TbMedicalInfo::getAddress, req.getAddress());
        queryWrapper.eq(StrUtil.isNotBlank(req.getPhone()), TbMedicalInfo::getPhone, req.getPhone());
        Page<TbMedicalInfo> page = baseMapper.selectPage(req.buildPage(), queryWrapper);
        return PageResult.of(page, TbMedicalInfoRespDTO.class);
    }

}
